package com.liuyucheng.designpattern.观察者模式.listener2;

public class Test {
    public static void main(String[] args) {

        // 事件源（被监听的对象）
        EventSource m1 = new EventSource();
        EventSource2 m2 = new EventSource2();
        // 监听器
        IEventListener mEventListener = new IEventListener() {

            @Override
            public void doEvent(IEvent arg) {
                if (arg.ClickButton()) {
                    System.err.println("you clicked button");
                }else if(arg.MoveMouse()){
                    System.err.println("you moved mouse");
                }
            }
        };

        // 注册监听器到事件源
        m1.setEventListener(mEventListener);
        m1.mouseEventHappened();

        // 注册监听器到事件源
        m2.setEventListener(mEventListener);
        m2.buttonEventHappened();
    }
}